JavaScript

A5.u.objectensure Method

Syntax

A5.u.object.ensure(object,path)

Arguments

objectobjectarray

The object or array to set the value in.

pathstringarray

The path to the value to set. If a string is passed in, the string should be formatted as it would be is accessed through javascript (for example "customer[1].name"). If an array, each subsequent entry in the array is the next leaf to access (such as ['customer',1,'name']).

valueany

The value to set.

Description

Set a value in an object or array from the passed in path.

Example

var data = {customer: [{name: 'Bob'},{name: 'Fred'}]};
A5.u.object.ensure(data,'customer[1].hobbies[0].name','Games');
// data = {customer: [{name: 'Bob'},{name: 'Tom', hobbies: [{name: 'Games'}]}]};